package com.sugon.springboot.controller;

import com.sugon.springboot.service.DynamicRouteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

@Slf4j
@RestController
@RequestMapping("/route/*")
public class DynamicRouteController {

    @Autowired
    private DynamicRouteService dynamicRouteService;

    @PostMapping("add")
    public boolean add(@RequestBody RouteDefinition routeDefinition) {
        return this.dynamicRouteService.add(routeDefinition);
    }

    @DeleteMapping("delete/{id}")
    public Mono<ResponseEntity<Object>> delete(@PathVariable String id) {
        return this.dynamicRouteService.delete(id);
    }

    @PutMapping("update")
    public boolean update(@RequestBody RouteDefinition routeDefinition) {
        return this.dynamicRouteService.update(routeDefinition);
    }
}
